package com.ruoyi.project.wechatprogram.configmode.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wechatprogram.configmode.domain.WxConfigMode;
import com.ruoyi.project.wechatprogram.configmode.service.IWxConfigModeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 配置项和配置参数Controller
 * 
 * @author sxchen
 * @date 2020-05-05
 */
@Controller
@RequestMapping("/configmode/configmode")
public class WxConfigModeController extends BaseController
{
    private String prefix = "configmode/configmode";

    @Autowired
    private IWxConfigModeService wxConfigModeService;

    @RequiresPermissions("configmode:configmode:view")
    @GetMapping()
    public String configmode()
    {
        return prefix + "/configmode";
    }

    /**
     * 查询配置项和配置参数列表
     */
    @RequiresPermissions("configmode:configmode:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxConfigMode wxConfigMode)
    {
        startPage();
        List<WxConfigMode> list = wxConfigModeService.selectWxConfigModeList(wxConfigMode);
        return getDataTable(list);
    }

    /**
     * 导出配置项和配置参数列表
     */
    @RequiresPermissions("configmode:configmode:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxConfigMode wxConfigMode)
    {
        List<WxConfigMode> list = wxConfigModeService.selectWxConfigModeList(wxConfigMode);
        ExcelUtil<WxConfigMode> util = new ExcelUtil<WxConfigMode>(WxConfigMode.class);
        return util.exportExcel(list, "configmode");
    }

    /**
     * 新增配置项和配置参数
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存配置项和配置参数
     */
    @RequiresPermissions("configmode:configmode:add")
    @Log(title = "配置项和配置参数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxConfigMode wxConfigMode)
    {
        return toAjax(wxConfigModeService.insertWxConfigMode(wxConfigMode));
    }

    /**
     * 修改配置项和配置参数
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WxConfigMode wxConfigMode = wxConfigModeService.selectWxConfigModeById(id);
        mmap.put("wxConfigMode", wxConfigMode);
        return prefix + "/edit";
    }

    /**
     * 修改保存配置项和配置参数
     */
    @RequiresPermissions("configmode:configmode:edit")
    @Log(title = "配置项和配置参数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxConfigMode wxConfigMode)
    {
        return toAjax(wxConfigModeService.updateWxConfigMode(wxConfigMode));
    }

    /**
     * 删除配置项和配置参数
     */
    @RequiresPermissions("configmode:configmode:remove")
    @Log(title = "配置项和配置参数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxConfigModeService.deleteWxConfigModeByIds(ids));
    }
}
